﻿using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FangDuShi_API.BLL
{
    /// <summary>
    /// 地区 逻辑类
    /// </summary>
    public class District
    {
        /// <summary>
        /// 地区DAL
        /// </summary>
        private DAL.District districtDAL = new DAL.District();
        public District()
        { }
        /// <summary>
        /// 获得省级数据列表
        /// </summary>
        public List<FangDuShi_API.Model.District> GetProvinceList()
        {
            DataSet ds = districtDAL.GetProvinceList();
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得某个地方的市级数据列表
        /// </summary>
        public List<FangDuShi_API.Model.District> GetCityList(string parentDistrictNo)
        {
            DataSet ds = districtDAL.GetCityList(parentDistrictNo);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<FangDuShi_API.Model.District> DataTableToList(DataTable dt)
        {
            List<FangDuShi_API.Model.District> modelList = new List<FangDuShi_API.Model.District>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                FangDuShi_API.Model.District model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = districtDAL.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }

    }
}
